package com.jiaxu.wifimusic;

import android.media.MediaPlayer;

import java.io.IOException;
import java.util.List;

/**
 * Created by jiaxu on 2016-3-25.
 */
public class PlayController {
    MediaPlayer player;
    private boolean isPause=true;
   public PlayController(MediaPlayer player){
        this.player=player;
    }
    public void play(){
        player.start();
        isPause=false;
    }
    public void pause(){
        player.pause();
        isPause=true;
    }
    public boolean isPause(){
        return isPause;
    }
    public void changeMusic(String url){
        player.reset();
        try {
            player.setDataSource(url);
            player.prepare();
        } catch (IOException e) {
            e.printStackTrace();
        }
        player.start();
        isPause=false;

    }
    public void nextMusic(List<MusicInfo> playList,int currentPosition) throws Exception{
        if (playList.get(++currentPosition)!=null){
            String url = playList.get(currentPosition).getUrl();
            player.reset();
            player.setDataSource(url);
            player.prepare();
            player.start();
            isPause=false;
            MainActivity.binder.setPosition(currentPosition);
        }
    }
}
